package cn.tedu.spring.boot.rabbitmq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {
    //定义队列、交换机、路由键(绑定键)
    public static final String TEST_QUEUE="test_queue";
    public static final String TEST_EXCHANGE="test_ex";
    public static final String TEST_ROUTE="test_route";

    //创建队列
    @Bean
    public Queue testQueue(){
        return new Queue(TEST_QUEUE);
    }
    //创建交换机
    @Bean
    public DirectExchange testExchange(){
        return new DirectExchange(TEST_EXCHANGE);
    }
    //绑定交换机和队列
    @Bean
    public Binding bindQueueAndExchange(){
        return BindingBuilder.bind(testQueue()).to(testExchange()).with(TEST_ROUTE);
    }
}
